﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using Lucene.Net.Index;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LynxWiki.DomainModel;
using LynxWiki.Search;


namespace LynxWiki.Tests.SearchTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestInitialize]
        public void TestSetup()
        {
            WikiRoot.RootDirectory = ConfigurationManager.AppSettings["WikiRoot"];
        }

        [TestMethod]
        public void GetAllIndexRecordsTest()
        {
            List<SearchData> sdl = LuceneSearch.GetAllIndexRecords().ToList();

            Assert.IsTrue(sdl.Count > 10);
        }

        [TestMethod]
        public void GetAllTagFreqVectorsTest()
        {
            ITermFreqVector[] tagFreqVectors = LuceneSearch.GetAllTagFreqVectors();

            Assert.IsTrue(tagFreqVectors != null);

            Dictionary<string, int> tagCount = new Dictionary<string, int>();
            foreach (ITermFreqVector item in tagFreqVectors) {
                if (item != null) {
                    foreach (string term in item.GetTerms()) {
                        if (tagCount.ContainsKey(term)) {
                            tagCount[term] += 1;
                        }
                        else {
                            tagCount.Add(term, 1);
                        }
                    }
                }
            }
            Assert.IsTrue(tagCount != null);
        }

        [TestMethod]
        public void GetTagCount()
        {
            Dictionary<string, int> tagCount = LuceneSearch.GetTagCount();
            Assert.IsTrue(tagCount.Count > 1);
        }

    }
}
